
package cn.edu.scau.cmi.hombio.domain;

import java.io.Serializable;

import java.lang.StringBuilder;

import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import org.codehaus.jackson.annotate.JsonIgnore;

import javax.xml.bind.annotation.*;

import javax.persistence.*;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllSales", query = "select mySale from Sale mySale"),
		@NamedQuery(name = "findSaleById", query = "select mySale from Sale mySale where mySale.id = ?1"),
		@NamedQuery(name = "findSaleByMemo", query = "select mySale from Sale mySale where mySale.memo = ?1"),
		@NamedQuery(name = "findSaleByMemoContaining", query = "select mySale from Sale mySale where mySale.memo like ?1"),
		@NamedQuery(name = "findSaleByPrimaryKey", query = "select mySale from Sale mySale where mySale.id = ?1"),
		@NamedQuery(name = "findSaleBySaleType", query = "select mySale from Sale mySale where mySale.saleType = ?1"),
		@NamedQuery(name = "findSaleBySaleTypeContaining", query = "select mySale from Sale mySale where mySale.saleType like ?1") })

@Table(catalog = "pig", name = "sale")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "pigRs/cn/edu/scau/cmi/hombio/domain", name = "Sale")
@XmlRootElement(namespace = "pigRs/cn/edu/scau/cmi/hombio/domain")
public class Sale implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "Id", nullable = false)
	@Basic(fetch = FetchType.EAGER)

	@Id @GeneratedValue
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "SaleType", nullable = false)
	@Basic(fetch = FetchType.EAGER)

	@XmlElement
	String saleType;
	/**
	 */

	@Column(name = "Memo")
	@Basic(fetch = FetchType.EAGER)

	@XmlElement
	String memo;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "EmployeeId", referencedColumnName = "Id", nullable = false) })
	@XmlTransient
	Employee employee;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "TaskId", referencedColumnName = "Id", nullable = false) })
	@XmlTransient
	Task task;
	/**
	 */
	@OneToMany(mappedBy = "sale", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.SalePig> salePigs;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setSaleType(String saleType) {
		this.saleType = saleType;
	}

	/**
	 */
	public String getSaleType() {
		return this.saleType;
	}

	/**
	 */
	public void setMemo(String memo) {
		this.memo = memo;
	}

	/**
	 */
	public String getMemo() {
		return this.memo;
	}

	/**
	 */
	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	/**
	 */
	@JsonIgnore
	public Employee getEmployee() {
		return employee;
	}

	/**
	 */
	public void setTask(Task task) {
		this.task = task;
	}

	/**
	 */
	@JsonIgnore
	public Task getTask() {
		return task;
	}

	/**
	 */
	public void setSalePigs(Set<SalePig> salePigs) {
		this.salePigs = salePigs;
	}

	/**
	 */
	@JsonIgnore
	public Set<SalePig> getSalePigs() {
		if (salePigs == null) {
			salePigs = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.SalePig>();
		}
		return salePigs;
	}

	/**
	 */
	public Sale() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(Sale that) {
		setId(that.getId());
		setSaleType(that.getSaleType());
		setMemo(that.getMemo());
		setEmployee(that.getEmployee());
		setTask(that.getTask());
		setSalePigs(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.SalePig>(that.getSalePigs()));
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("saleType=[").append(saleType).append("] ");
		buffer.append("memo=[").append(memo).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Sale))
			return false;
		Sale equalCheck = (Sale) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
